package com.app.base.service.auth.controller;



import com.app.base.model.dto.RegisterPageDto;
import com.app.base.service.auth.entity.SysUser;
import com.app.base.service.auth.service.SysUserService;
import com.app.base.utlis.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 *登录表前端控制器
 * @author yuhag
 * @since 2022-05-07
 */
@RestController
@RequestMapping("/auth")
@Api(tags = "系统用户")
public class SysUserController {

    @Resource
    private SysUserService userService;

    @GetMapping("getToken")
    @ApiOperation("获取令牌")
    public Result getToken() {
        return userService.getToken();
    }

    @PostMapping("login")
    @ApiOperation("登录")
    public Result login(@RequestBody SysUser user) {
        return userService.login(user);
    }

    @GetMapping("info")
    @ApiOperation("获取登录人信息")
    public Result getInfo(@RequestParam("token")String token){
        return userService.info(token);
    }

    @PostMapping("register")
    @ApiOperation("注册")
    public Result register(@RequestBody RegisterPageDto registerPageDto){
        return userService.register(registerPageDto);
    }

    @PostMapping("editUser")
    @ApiOperation("用户信息修改")
    public Result editUser(@RequestBody SysUser user) {
        userService.updateById(user);
        return Result.ok().message("用户修改成功");
    }

}


